#
# This file is used to executed given unit test commands on a previously
# initialize Android device emulator instance
#

# Restore the required settings of the CMake configuration step
INCLUDE(@CMAKE_BINARY_DIR@/dcmtkCTestConfig.cmake NO_POLICY_SCOPE)

# Load required functions for accessing the Android device emulator
INCLUDE(${DCMTK_CMAKE_INCLUDE}CMake/dcmtkUseAndroidSDK.cmake)

# Restore the Android device emulator instance handle
SET(DCMTK_ANDROID_EMULATOR_INSTANCE @DCMTK_ANDROID_EMULATOR_INSTANCE@)

# Run the actual testcase on the remote device
DCMTK_ANDROID_SHELL(DCMTK_ANDROID_EMULATOR_INSTANCE
    COMMAND "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:${ANDROID_TEMPORARY_FILES_LOCATION}" ${DCMTK_CTEST_TESTCASE_COMMAND}
    WORKING_DIRECTORY ${ANDROID_TEMPORARY_FILES_LOCATION}
    RESULT_VARIABLE RESULT
)

# We cannot forward the result value to CMake, so print it instead and let CMake
# return with code '1' or whatever it deems appropriate to notify about an error.
IF(RESULT)
    MESSAGE(FATAL_ERROR "Test command returned: ${RESULT}")
ENDIF()
